package com.serviceImpl;

import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.dao.manager.MaintenanceMapper;
import com.pojo.Maintenance;
import com.service.MaintenanceService;
import com.utils.UUIDUtils;

@Service
public class MaintenanceServiceImp implements MaintenanceService{

	@Resource
	private MaintenanceMapper maintenanceMapper;
	@Override
	public int addMaintenanceInfo(Map<String, String> paramsMap) {
		try {
			String uuid = UUIDUtils.getUUID();
			Maintenance entity = new Maintenance();
			entity.setId(Integer.parseInt(paramsMap.get("id")));
			entity.setUuid(uuid);
			entity.setMaintainer(paramsMap.get("maintainer"));
			entity.setMaintainItems(paramsMap.get("maintainItems"));
			entity.setCreatetime(new Date());
			maintenanceMapper.addMaintenanceInfo(entity);
			return 1;
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
	}
	@Override
	public int deleteMaintenanceInfo(Map<String, String> paramsMap) {
		try {
			return maintenanceMapper.deleteMaintenanceInfo(paramsMap);
		} catch (Exception e) {
			e.printStackTrace();
			return -2;
		}
	}
	@Override
	public int updateMaintenanceInfo(Map<String, String> paramsMap) {
		try {
			String uuid = paramsMap.get("uuid");
			Maintenance entity = new Maintenance();
			entity.setId(Integer.parseInt(paramsMap.get("id")));
			entity.setUuid(uuid);
			entity.setMaintainer(paramsMap.get("maintainer"));
			entity.setMaintainItems(paramsMap.get("maintainItems"));
			entity.setCreatetime(new Date());
			maintenanceMapper.updateMaintenanceInfo(entity);
			return 1;
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
	}
	@Override
	public List<Map<String, String>> getMaintenanceInfo(Map<String, String> paramsMap) {
		String page = paramsMap.get("page");
		if (page == null || "".equals(page)) {
			page = "1";
		}
		String num = paramsMap.get("num");
		if (num == null || "".equals(num)) {
			num = "10";
			paramsMap.put("num", num);
		}
		int start = (Integer.parseInt(page) - 1) * Integer.parseInt(num);
		paramsMap.put("start", start + "");
		return maintenanceMapper.getMaintenanceInfo(paramsMap);
	}
	@Override
	public List<Map<String, String>> getMaintenanceByUuid(Map<String, String> paramsMap) {
		return maintenanceMapper.getMaintenanceByUuid(paramsMap.get("uuid"));
	}
}
